<script type="text/javascript" src="/bootstrap_select/bootstrap-select.js"></script>
<link rel="stylesheet" type="text/css" href="/bootstrap_select/bootstrap-select.css">
<style>
    .table>thead>tr>th{background: #ddd;}
    .table>tbody>tr>td ,.table>thead>tr>th{padding:8px;line-height:2;vertical-align:bottom;border-bottom:1px solid #ddd;}
    .col-md-12{background:#ffffff;}



    .modal-body .form-group>label{margin-left: 35px;float:left;margin-right: 10px;padding-top: 8px;width: 100px;}
    .modal-body .form-group>input{width: 65%;}

</style>
<body>
<div style="height: 50px;line-height: 50px;font-size: 16px;">
    <b>医生列表</b>
</div>
<table class="table table-hover">
    <thead>
    <tr>
        <th>ID</th>
        <th>姓名</th>
        <th>所属机构</th>
        <th>所在科室</th>
        <th>联系电话</th>
        <th>标签</th>
        <th>擅长领域</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    @foreach ($result as $item)
        <tr>
            <td>{{$item->id}}</td>
            <td>
                @if(empty($item->d_id))
                    {{$item->u_name}}
                @else
                    {{$item->name}}
                @endif
            </td>
            <td>{{$item->institution_id}}</td>
            <td>{{$item->department_id}}</td>
            <td>{{$item->contact}}</td>
            <td>{{$item->tag}}</td>
            <td style="width: 35%;">{{$item->good_at}}</td>
            <td><button type="button" data_id = "{{$item->id}}" data_name = "<?php echo empty($item->d_id) ? $item->u_name : $item->name;?>" institution_id = "{{$item->institution_id}}" department_id = "{{$item->department_id}}" contact = "{{$item->contact}}" good_at = "{{$item->good_at}}" tag = "{{$item->tag}}" class="btn btn-success btn_bound">编辑</button></td>
        </tr>
    @endforeach
    </tbody>
</table>
{{ $result->links() }}


<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="border-radius: 10px;margin-top:30%;">
            <div class="modal-header" style="background: #3c8dbc;color: #fff;border-top-left-radius:10px;border-top-right-radius: 10px;">
                <h4 class="modal-title" id="myModalLabel">新增</h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label for="txt_departmentname">姓名：</label>
                    <input type="text" name="name" class="form-control" id="name"  placeholder="请输入医生姓名">
                </div>
                <div class="form-group">
                    <label for="txt_departmentname">所属机构：</label>
                    <input type="text" name="institution_id" class="form-control" id="institution_id"  placeholder="请输入医生所属机构">
                </div>
                <div class="form-group">
                    <label for="txt_departmentname">所在科室：</label>
                    <input type="text" name="department_id" class="form-control" id="department_id"  placeholder="请输入医生所在科室">
                </div>
                <div class="form-group">
                    <label for="txt_departmentname">联系电话：</label>
                    <input type="text" name="contact" class="form-control" id="contact"  placeholder="请输入医生联系电话">
                </div>
                <div class="form-group">
                    <label for="txt_departmentname">标签：</label>
                    <input type="text" name="tag" class="form-control" id="tag"  placeholder="请输入医生标签">
                </div>
                <div class="form-group">
                    <label for="txt_parentdepartment">擅长领域：</label>
                    <textarea rows="5" style="width: 65%;" id="good_at" class="form-control"></textarea>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" id="btn_cancel" class="btn btn-default" data-dismiss="modal">取 消</button>
                <button type="button" id="btn_submit" class="btn btn-primary" data-dismiss="modal"  style="margin-left: 20px;">确 定</button>
            </div>
        </div>
    </div>
</div>

</body>

<script>
    $('.btn_bound').on('click',function () {
        $('#name').val($(this).attr('data_name'));
        $('#institution_id').val($(this).attr('institution_id'));
        $('#department_id').val($(this).attr('department_id'));
        $('#contact').val($(this).attr('contact'));
        $('#good_at').val($(this).attr('good_at'));
        $('#tag').val($(this).attr('tag'));
        $("#myModalLabel").text("编辑");
        $('#myModal').modal();
    })

    //提交编辑信息
    $('#btn_submit').on('click',function () {
        var id = $('.btn_bound').attr('data_id');
        var name = $('#name').val();
        var institution_id = $('#institution_id').val();
        var department_id = $('#department_id').val();
        var contact = $('#contact').val();
        var good_at = $('#good_at').val();
        var tag = $('#tag').val();
        $.ajax({
            url : "{{admin_url('doctor/update')}}",
            type:'post',
            dataType:'json',
            data:{'id':id,'name':name,'institution_id':institution_id,'department_id':department_id,'contact':contact,'good_at':good_at,'tag':tag},
            success:function(result){
                if ( result.code != 0 ) {
                    layer.msg('修改失败')
                }else{
                    window.location.reload();
                }
            }
        });

    })
</script>

